package com.good.cm.controller;

import com.good.cm.service.UserService;
import com.good.cm.utils.CookieUtil;
import com.good.cm.vo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Controller
public class ViewsController {

    @Resource
    private UserService userService;
    //首页
    @RequestMapping("home")
    public  String home(){
        return "home";
    }
    //登录页
    @RequestMapping("login")
    public  String login(){
        return "login";
    }
   //主框架页面
    @RequestMapping("index")
    public  String index(HttpServletRequest request){
        System.out.println("访问index；");
        String value= CookieUtil.getCookieUserId(request);
        System.out.println("获取cookie中值；" + value);
        User u = userService.getUser(value);
        request.setAttribute("user",u);
        System.out.println("当前用户：" + u);
        return "index";
    }

    //--------------------子页面----------------------------
    //患者列表页面
    @RequestMapping("patient/ListView")
    public String patientListView(HttpServletRequest request)
    {
        return "pat/listView";
    }
    //忘记密码页面
    @RequestMapping("user/toPasswordView")
    public String toPasswordPage(String id, HttpServletRequest request){
        request.setAttribute("id",id);
        return "user/password";
    }
    //添加患者页面
    @RequestMapping("patient/addPatientView")
    public String addPatient(String pvid, HttpServletRequest request){
        request.setAttribute("pvid",pvid);
        return "pat/addpatient";
    }
}
